package com.bytedance.scenedemo.navigation.template;

import com.bytedance.scene.ui.template.AppCompatScene;
import com.bytedance.scenedemo.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.AttrHelper;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.PopupDialog;

public class DefaultScene extends AppCompatScene {
    @Override
    protected Component onCreateContentView(LayoutScatter inflater, ComponentContainer container, Intent savedInstanceState) {
        return null;
    }

    @Override
    public void onActivityCreated(Intent savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setTitle("AppCompatScene");
        slMore.setVisibility(Component.VISIBLE);
        slMore.setClickedListener(component -> {
            Component cptDialog=LayoutScatter.getInstance(getActivity())
                    .parse(ResourceTable.Layout_custom_popup_dialog,null,false);
            PopupDialog popupDialog=new PopupDialog(getActivity(),null)
                    .setCustomComponent(cptDialog);
            popupDialog.setCornerRadius(5);
            popupDialog.setDialogListener(() -> {
                popupDialog.hide();
                return false;
            });
            popupDialog.setBackColor(Color.TRANSPARENT);
            popupDialog.setTransparent(true);
            popupDialog.showOnCertainPosition(LayoutAlignment.RIGHT|LayoutAlignment.TOP,0,0);

            cptDialog.setClickedListener(component1 -> {
                popupDialog.hide();
            });

            AnimatorProperty ap=new AnimatorProperty();
            ap.setTarget(cptDialog)
                    .moveFromX(AttrHelper.vp2px(170f,getActivity())).moveToX(0)
                    .alphaFrom(0).alpha(1)
                    .setDuration(100).start();

        });

    }
}
